package cosc617_blackteam;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * Class representing a list of MenuItems
 * @author Laura Semesky
 * 
 * 
 * edited by Anton on 4/12/2013 - updated addMenuItem method to reflect changes to the menuItem class. 
 */

public class Menu implements Iterable<MenuItem>{
	private ArrayList<MenuItem> menuItems;
	
     
        
	public Menu(){
		menuItems = new ArrayList<MenuItem>();
	}
	
	
	/**
	 * @return an iterator of all the items in the menu
	 */
	public I_MenuIterator getDefaultMenuIterator(){
		return new DefaultMenuIterator(menuItems);	
	}
	
	/**
	 * @param price the upper price limit of menu items to be returned
	 * @return an iterator of all the items in the menu with a price <= input price
	 */
	public I_MenuIterator getPriceMenuIterator(BigDecimal price){
		return new PriceMenuIterator(menuItems, price);
	}
	
	
	/**
	 * @param ingredient the main ingredient of all menu items to be returned
	 * @return an iterator of all items in the menu with the given ingredient
	 */
	public I_MenuIterator getIngredientMenuIterator(String ingredient){
		return new IngredientMenuIterator(menuItems, ingredient);
	}
	
	/**
	 * @return An iterator of all the heart healthy items in the menu
	
	public I_MenuIterator getHeartHealthyMenuIterator(){
		return new HeartHealthyMenuIterator(menuItems);
	}
         */
        /**
	 * @return An iterator of all the items with a specialAttribute in the menu
	 */
	public I_MenuIterator getSpecialAttributeMenuIterator(MenuSpecialAttribute specialAttribute){
		return new SpecialAttributeMenuIterator(menuItems, specialAttribute);
	}
	
	/**
	 * @param i MenuItem to be added to the list
	 * Checks if item is in the list and if it is not adds it
         * updated 4/17/2013 - I made addMenuItem(MenuItem i) public so that the command classes could pass menu items around instead of having to pass each part of menuItem around
	 */
	public void addMenuItem(MenuItem i){
		if(!menuItems.contains(i))
			menuItems.add(i);
	}
	

        /**
	 * Creates a MenuItem with given inputs and calls function to add to the list
	 * @param name Name of the Menu Item
	 * @param mainIngredient The main ingredient of the menu item
	 * @param priceString String representing the price of the MenuItem 
         * @param specialAttributes String[] an array containing any special attributes that the menu item has.
	 */
	public void addMenuItem(String name, String[] ingredients, String category, String priceString, MenuSpecialAttribute[] specialAttributes, int minutesToCook){
		ArrayList<String>ingredientList = new ArrayList<String>();
		for (String ingredient : ingredients)
			ingredientList.add(ingredient);
		MenuItem i = new MenuItem(name, ingredientList, category, priceString, specialAttributes, minutesToCook);
		addMenuItem(i);
                
	}
       	
	/**
	 * Generates a new menu with the following menu item information
	 */
	public void generateDefaultMenu(){
		
		addMenuItem("BLT", new String[]{"Bacon", "Lettuce", "Tomato", "Mayonaise"}, "Sandwich","5.95", null, 3);
		addMenuItem("Turkey Sandwich", new String[]{"Turkey", "Mayonaise", "American Cheese"}, "Sandwich", "6.25", new MenuSpecialAttribute[] {MenuSpecialAttribute.HEARTHEALTHY}, 3);
		addMenuItem("Roast Beef Sandwich", new String[]{"Roast Beef", "Mayonaise", "Lettuce"}, "Sandwich", "7.00", new MenuSpecialAttribute[] {MenuSpecialAttribute.HEARTHEALTHY}, 3);
		addMenuItem("Hamburger", new String[]{"Ground Beef", "Lettuce", "Tomato", "Pickle", "Onion"}, "Burger","5.25", null, 5);
		addMenuItem("Cheeseburger", new String[]{"Ground Beef", "Lettuce", "Tomato", "Pickle", "Onion", "Cheddar Cheese"},"Burger", "6.25", null, 5);
		addMenuItem("Garden Salad", new String[]{"Lettuce", "Tomato", "Crouton", "Cheddar Cheese", "Salad Dressing", "Onion"}, "Salad", "3.75", new MenuSpecialAttribute[] {MenuSpecialAttribute.HEARTHEALTHY, MenuSpecialAttribute.VEGETARIAN}, 1);
		addMenuItem("Ceasar Salad", new String[]{"Lettuce", "Crouton", "Parmesan Cheese", "Ceasar Dressing"}, "Salad", "4.50", new MenuSpecialAttribute[] {MenuSpecialAttribute.HEARTHEALTHY, MenuSpecialAttribute.VEGETARIAN},1 );
	
	}
	
	/**
	 * Finds menu item with the given name
	 * @return MenuItem if found or null if not
	 */
	public MenuItem findMenuItem(String s){
		
		for(MenuItem item : menuItems)
			if (item.toString().compareToIgnoreCase(s) == 0)
				return item;
		return null;
		
	}

@Override
public Iterator<MenuItem> iterator() {
	// TODO Auto-generated method stub
	return getDefaultMenuIterator();
}
        
}
